<template>
  <div>
    <i
      class="el-icon-circle-plus-outline"
      @click="dialogFormVisible = true"
    ></i>
    <el-dialog
      title="添加/修改图书"
      :visible.sync="dialogFormVisible"
      @close="clear"
    >
      <el-form v-model="form" style="text-align: left" ref="dataForm">
        <el-form-item label="书名" :label-width="formLabelWidth" prop="title">
          <el-input
            v-model="form.title"
            autocomplete="off"
            placeholder="不加《》"
          ></el-input>
        </el-form-item>
        <el-form-item label="作者" :label-width="formLabelWidth" prop="author">
          <el-input v-model="form.author" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="出版日期"
          :label-width="formLabelWidth"
          prop="date"
        >
          <el-input v-model="form.date" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="出版社" :label-width="formLabelWidth" prop="press">
          <el-input v-model="form.press" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="封面" :label-width="formLabelWidth" prop="cover">
          <el-input
            v-model="form.cover"
            autocomplete="off"
            placeholder="图片 URL"
          ></el-input>
        </el-form-item>
        <el-form-item label="简介" :label-width="formLabelWidth" prop="abs">
          <el-input
            type="textarea"
            v-model="form.abs"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="分类" :label-width="formLabelWidth" prop="cid">
          <el-select v-model="form.category.id" filterable placeholder="请选择">
            <el-option
              v-for="item in option"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="id" style="height: 0">
          <el-input
            type="hidden"
            v-model="form.id"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="danger"
          icon="el-icon-close"
          @click="dialogFormVisible = false" 
           
          >取 消</el-button
        >
        <el-button type="success" icon="el-icon-check" @click="onSubmit"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- <el-alert
    title="成功提示的文案"
    type="success"
    effect="dark"
    v-show="finish">
  </el-alert> -->

    <!-- <editsuccess ref="editsuccess"></editsuccess> -->
  </div>
</template>
  
  <script>

export default {

  name: "EditForm",
  data() {
    return {
      // 控制弹窗是否显示的
      dialogFormVisible: false,
      form: {
        id: "",
        title: "",
        author: "",
        date: "",
        press: "",
        cover: "",
        abs: "",
        category: {
          id: "",
          name: "",
        },
        finish: false,
      },
      option: [
        { label: "文学", value: 1 },
        { label: "流行", value: 2 },
        { label: "文化", value: 3 },
        { label: "生活", value: 4 },
        { label: "经管", value: 5 },
        { label: "科技", value: 6 },
      ],
      formLabelWidth: "120px",
    };
  },
  methods: {
    clear() {
      console.log("清楚表单");
      this.form = {
        id: "",
        title: "",
        author: "",
        date: "",
        press: "",
        cover: "",
        abs: "",
        category: "",
      };
    },
    onSubmit() {
      // this.$refs.editsuccess.dialogVisible = true

      // this.finish=true
      this.$axios
        .post("/books", {
          id: this.form.id,
          cover: this.form.cover,
          title: this.form.title,
          author: this.form.author,
          date: this.form.date,
          press: this.form.press,
          abs: this.form.abs,
          category: this.form.category,
        })
        .then((resp) => {
          if (resp && resp.status === 200) {
            this.dialogFormVisible = false;
            this.openadd();
            this.$emit("onSubmit");
           
          }
        });
    },
    openadd() {
      this.$message({
        message: "成功添加/修改",
        type: "success",
      });
    },
  },
};
</script>
  
  <style scoped>
.el-icon-circle-plus-outline {
  margin: 50px 0 0 20px;
  font-size: 100px;
  float: left;
  cursor: pointer;
}
el-alert {
  position: absolute;
  margin-top: -100px;
}
</style>
  
  
  